<?php
/**
 * @file sqlite3.php
 * @package 
 * @subpackage 
 * @version $id: 0.1 UTF-8 2009-5-26 下午09:14:42 $
 * @author LD King (mifunny.info)
 * @copyright Copyright (c) 2007 - 2009 MiFunny China Inc. (http://mifunny.info)
 * create table donghua(id INTEGER PRIMARY KEY AUTOINCREMENT,abc,efg);
 */
$filename = dirname(__FILE__).'/abc';
$sqlite_dsn = 'sqlite:'.dirname(__FILE__).'/abc.db';
//echo $sqlite_dsn;

try {
	$sqlite_dbh = new PDO($sqlite_dsn, null, null, array(PDO::ATTR_PERSISTENT => true));
	echo "SQLite PDO 连接成功<br/>";
	$sqlite_dbh->query('PRAGMA encoding = "UTF-8"');
	$sqlite_dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch (Exception $ex) {
	die ("SQLite Connent Error!: " . $ex->getMessage() . "<br/>");
}

@ $fb = fopen($filename,'rb',TRUE); //open file
if (!$fb) {
	exit("<p>I can't open this file: ".$filename."<p>");
}else {echo "文本打开成功<br/>";}

for ($n = 1; !feof($fb); $n++) { //count poems
	$tang = fgets($fb, 999);
	
//	echo $n.' = '.$tang.'<br />';
	if ($n == 1) $str1 = $tang;
	elseif ($n == 2) $str2 = $tang;
	elseif ($n == 3) {
		$n = 0;
		$sqlInsert = "INSERT INTO donghua VALUES(null, '".$str1."', '".$str2."' )";
		if ($sqlite_dbh->exec($sqlInsert) == 1){ echo $str2." ------> 写入 SQLite数据库成功！<br />";
		}else { echo " ------> 写入 SQLite数据库<span style=\"color:red;\">失败</span>！<br />".$sqlInsert; }
	} //if END
} //

fclose($fb);
$sqlite_dbh = null;

?>
<div style="text-align:center;margin:75px 0 25px 0;position:relative;">
	<p>Copyright &copy; 2008 - 2009, <a href="http://mifunny.info/">水草树</a>, All right reserved.</p>
	<p><a href="index.php">首页</a> | <a href="sqlite3.php">录入数据</a></p>
</div>